package com.zht.controller;




import cn.hutool.core.img.ImgUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.ByteArrayOutputStream;
import java.io.File;

@Slf4j
@RestController
public class QrCodeController {
    @Value("${custom.qrcode.content}")
    private String content;

    @GetMapping("/qrcode")
    public ResponseEntity<byte[]> generateQrCode(){
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        QrCodeUtil.generate(content, 200, 200, ImgUtil.IMAGE_TYPE_JPG,bos);

        byte[] bytes = bos.toByteArray();
        HttpHeaders httpHeader = new HttpHeaders();
        httpHeader.setContentType(MediaType.IMAGE_JPEG);
        return new ResponseEntity<>(bytes,httpHeader, HttpStatus.OK);
    }
}
